package view;


import interfaces.ViewPanel;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JProgressBar;

import control.BudgetManager;
import control.ExpenseManager;
import control.IncomeManager;

import utils.DataFormat;
import view.BackgroundPanel;

import java.awt.Font;

//@author A0081236L
public class OverviewPanel extends BackgroundPanel implements ViewPanel {
	
	private Image logo;
	private Image piggyBank;
	private JLabel lbl_budget;
	private JLabel lbl_expenses;
	private JLabel lbl_spent;
	private JLabel label_amount;
	private BudgetManager _budgetMan;
	private IncomeManager _incomeMan;
	private ExpenseManager _expenseMan;	
	private JProgressBar jProgressBar1;
	private JButton goButton;
	private String budget;
	
	public OverviewPanel(BudgetManager budgetMan, IncomeManager incomeMan, ExpenseManager expenseMan){		
		   super();
			Color newColor = new Color(255, 255, 255);
			this.setBackground(newColor);
			this.setLayout(null);
		   
		   _budgetMan = budgetMan;
		   _incomeMan = incomeMan;
		   _expenseMan = expenseMan;
		   logo = Toolkit.getDefaultToolkit().getImage("src/images/EzXpns Logo.png");
		   piggyBank = Toolkit.getDefaultToolkit().getImage("src/images/Piggy-Bank.png");
		   
		   lbl_budget = new JLabel("Balance");
		   lbl_budget.setForeground(new Color(128, 0, 128));
		   lbl_budget.setFont(new Font("Lithos Pro Regular", Font.BOLD | Font.ITALIC, 30));
		   lbl_budget.setBounds(655, 50, 200, 50);
		   this.add(lbl_budget);
		   
		   budget = DataFormat.returnTwoDecimals(_budgetMan.get_totalBalance());
		    label_amount = new JLabel();
		    label_amount.setForeground(new Color(102, 51, 0));
			label_amount.setFont(new Font("Levenim MT", Font.ITALIC, 22));
			label_amount.setBounds(655, 100, 200, 50);
			//label_5.setHorizontalAlignment(SwingConstants.TRAILING);
			this.add(label_amount);
	
			lbl_expenses = new JLabel("Family Expense Manager");
			lbl_expenses.setForeground(new Color(0, 0, 139));
			lbl_expenses.setFont(new Font("Lithos Pro Regular", Font.BOLD, 24));
			lbl_expenses.setBounds(50, 220, 353, 50);
			this.add(lbl_expenses);	
			
			lbl_spent = new JLabel("Expenses over Income");
			lbl_spent.setForeground(new Color(51, 0, 102));
			lbl_spent.setFont(new Font("Lithos Pro Regular", Font.PLAIN, 16));
			lbl_spent.setBounds(50, 284, 200, 39);
			this.add(lbl_spent);	
			jProgressBar1 = new JProgressBar(0,100);
			this.add(jProgressBar1);
			updateAll();
			
			
		  }

		  public void paintComponent(Graphics g){
		   super.paintComponent(g);
		   // Draw our Image object.
		   g.drawImage(logo,50,10, this); 
		   g.drawImage(piggyBank, 550, 50, this);
		   //g.setColor(Color.BLUE);
		   //g.drawOval(0, 0, 200, 200);

		  }

		//@author A0098891H
		  public void updateAll() {
				double value;
				String prompt = "";
				if(_incomeMan.getTotalAmountOfAll()==0)
				{
					value = 0;
					prompt = "no income";
				}
				else 
				{
					value = _expenseMan.findAmountTotal()/_incomeMan.getTotalAmountOfAll();
					value*=100;
					prompt = (int)(value)+"%";
				}
				jProgressBar1.setBounds(248, 292, 278, 23);
				jProgressBar1.setValue((int) value);
				jProgressBar1.setStringPainted(true);
				jProgressBar1.setString(prompt);
				if(value>80)
				{
					jProgressBar1.setForeground(Color.red);
				}
				else
				{
					jProgressBar1.setForeground(Color.blue);
				}
				budget = DataFormat.returnTwoDecimals(_budgetMan.get_totalBalance());
				label_amount.setText("$" + budget);
		  }

		@Override
		public void updateExpense() {
			// TODO Auto-generated method stub
			updateAll();
		}

		@Override
		public void updateIncome() {
			// TODO Auto-generated method stub
			updateAll();
		}

		@Override
		public void updateLoan() {
			// TODO Auto-generated method stub
			updateAll();
		}

		@Override
		public void updateCategory() {
			// TODO Auto-generated method stub
			updateAll();
		}

		@Override
		public void updateMember() {
			// TODO Auto-generated method stub
			updateAll();
		}

		@Override
		public void updatePayMethod() {
			// TODO Auto-generated method stub
			updateAll();
		}

		@Override
		public void updateTable() {
			// TODO Auto-generated method stub
			updateAll();
			
		}
}
	

